<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/24
  Time: 23:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
    $(function () {
        $("#pageSearch").click(function () {
            var pageNo = $("#pn_input").val();

            //javaScript语言当中提供了一个location地址栏对象
            //它有一个属性叫href，它可以获取浏览器地址栏中的地址
            //herf属性可读可写
            location.href ="${pageScope.basePath}${requestScope.page.url}&pageNo="+pageNo;
        })
    })
</script>
<div id="page_nav">
    <%--当第一页的时候，首页和上一页不显示--%>
    <c:if test="${requestScope.page.pageNo>1}">
        <a href="${requestScope.page.url}&pageNo=1">首页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo-1}">上一页</a>
    </c:if>

    <c:choose>
        <c:when test="${requestScope.page.totalPage<=5}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="${requestScope.page.totalPage}"></c:set>
        </c:when>
        <c:when test="${requestScope.page.totalPage>5}">
            <c:choose>
                <c:when test="${requestScope.page.pageNo<=3}">
                    <c:set var="begin" value="1"></c:set>
                    <c:set var="end" value="5"></c:set>
                </c:when>
                <c:when test="${requestScope.page.pageNo>requestScope.page.totalPage-3}">
                    <c:set var="begin" value="${requestScope.page.totalPage-4}"></c:set>
                    <c:set var="end" value="${requestScope.page.totalPage}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="begin" value="${requestScope.page.pageNo-2}"></c:set>
                    <c:set var="end" value="${requestScope.page.pageNo+2}"></c:set>
                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>

    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${i==requestScope.page.pageNo}">
            【${i}】
        </c:if>
        <c:if test="${i!=requestScope.page.pageNo}">
            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
        </c:if>
    </c:forEach>

    <%--当最后一页的时候，末页和下一页不显示--%>
    <c:if test="${requestScope.page.pageNo<requestScope.page.totalPage}">
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo+1}">下一页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.totalPage}">末页</a>
    </c:if>
    共${requestScope.page.totalPage}页，${requestScope.page.totalCount}条记录 到第<input value="${requestScope.page.pageNo}" name="pn" id="pn_input"/>页
    <input type="button" value="确定" id="pageSearch">
</div>
